widget: Add new allocation accessors
authorTimm Bäder <mail@baedert.org>
Fri, 16 Jun 2017 16:08:04 +0000 (18:08 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 20 Jul 2017 01:27:14 +0000 (21:27 -0400)
gtk/gtkwidget.c
gtk/gtkwidgetprivate.h

index a454702307be8c94495dd7aac3b8888d968478ab..c605361d4dfe97a337db7d0e6362a093c4db6d31 100644 (file)
@@ -13528,6 +13528,57 @@ gtk_widget_get_allocation (GtkWidget     *widget,
   *allocation = priv->allocation;
 }
 
+void
+gtk_widget_get_outer_allocation (GtkWidget    *widget,
+                                 GdkRectangle *allocation)
+{
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+  GtkBorder margin;
+  GtkCssStyle *style;
+
+  style = gtk_css_node_get_style (priv->cssnode);
+  get_box_margin (style, &margin);
+
+  *allocation = priv->allocation;
+
+  allocation->x += margin.left;
+  allocation->y += margin.top;
+  allocation->width -= margin.left + margin.right;
+  allocation->height -= margin.top + margin.bottom;
+}
+
+void
+gtk_widget_get_own_allocation (GtkWidget    *widget,
+                               GdkRectangle *allocation)
+{
+  GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+  GtkBorder margin, border, padding;
+  GtkCssStyle *style;
+
+  style = gtk_css_node_get_style (priv->cssnode);
+  get_box_margin (style, &margin);
+  get_box_border (style, &border);
+  get_box_padding (style, &padding);
+
+  allocation->x = -padding.left - border.left;
+  allocation->y = -padding.top - border.top;
+  allocation->width = priv->allocation.width - margin.left - margin.right;
+  allocation->height = priv->allocation.height -margin.top - margin.bottom;
+}
+
+void
+gtk_widget_get_content_size (GtkWidget *widget,
+                             int       *width,
+                             int       *height)
+{
+  GtkAllocation alloc;
+
+  gtk_widget_get_content_allocation (widget, &alloc);
+
+  *width = alloc.width;
+  *height = alloc.height;
+}
+
 void
 gtk_widget_get_content_allocation (GtkWidget     *widget,
                                    GtkAllocation *allocation)
index 6702c8653f7a13c1362c200653ee7a9214d7152e..18f7dc4a737751dcf119f8148277cfd672ba850c 100644 (file)
@@ -324,7 +324,13 @@ void              gtk_widget_get_border_allocation         (GtkWidget        *wi
                                                             GtkAllocation    *allocation);
 void              gtk_widget_get_margin_allocation         (GtkWidget        *widget,
                                                             GtkAllocation    *allocation);
-
+void              gtk_widget_get_outer_allocation          (GtkWidget        *widget,
+                                                            GtkAllocation    *allocation);
+void              gtk_widget_get_own_allocation            (GtkWidget        *widget,
+                                                            GtkAllocation    *allocation);
+void              gtk_widget_get_content_size              (GtkWidget        *widget,
+                                                            int              *width,
+                                                            int              *height);
 
 GtkWidget *       gtk_widget_common_ancestor               (GtkWidget *widget_a,
                                                             GtkWidget *widget_b);